// TinyMsgInterface.h : Declaration of the CTinyMsgInterface

#pragma once
#include "resource.h"       // main symbols

#include "TinyMsgTool.h"
#include "_ITinyMsgInterfaceEvents_CP.h"


#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif


#include "TinyMsg.h"
#include "TinyTCPClient.h"
#include "tinymsg.h"
// CTinyMsgInterface

class ATL_NO_VTABLE CTinyMsgInterface :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CTinyMsgInterface, &CLSID_TinyMsgInterface>,
	public IConnectionPointContainerImpl<CTinyMsgInterface>,
	public CProxy_ITinyMsgInterfaceEvents<CTinyMsgInterface>,
	public IDispatchImpl<ITinyMsgInterface, &IID_ITinyMsgInterface, &LIBID_TinyMsgToolLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CTinyMsgInterface()
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_TINYMSGINTERFACE)


BEGIN_COM_MAP(CTinyMsgInterface)
	COM_INTERFACE_ENTRY(ITinyMsgInterface)
	COM_INTERFACE_ENTRY(IDispatch)
	COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()

BEGIN_CONNECTION_POINT_MAP(CTinyMsgInterface)
	CONNECTION_POINT_ENTRY(__uuidof(_ITinyMsgInterfaceEvents))
END_CONNECTION_POINT_MAP()


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
	}

public:
	TinyCC::TCP::CTinyTCPClient m_client;

public:
	STDMETHOD(connect)(BSTR IP, LONG port, VARIANT_BOOL* result);
public:
	HANDLE m_hRecHandle;
public:
	STDMETHOD(send)(VARIANT_BOOL* result);
public:
	STDMETHOD(nextMsg)(VARIANT_BOOL* result);
public:
	STDMETHOD(clear)(void);
public:
	STDMETHOD(setMsgIndex)(LONG index);
public:
	STDMETHOD(setMsgItem)(LONG item);
public:
	TinyCC::msg::CTinyMsg m_tinyMsg;
public:
	STDMETHOD(talk)(VARIANT_BOOL* result);
public:
	STDMETHOD(getMsgIndex)(LONG* value);
public:
	STDMETHOD(getMsgItem)(LONG* value);
public:
	STDMETHOD(getDefaultParamByIndex)(LONG index, BSTR* value);
public:
	STDMETHOD(getDefaultParamCount)(LONG* value);
	STDMETHOD(setDefaultParamByIndex)(LONG index, BSTR value, VARIANT_BOOL* ret);
	STDMETHOD(shutdown)(BSTR* succ);
	STDMETHOD(getExternalParamKeyCount)(LONG index, LONG* count);
	STDMETHOD(getExternalParamValueCount)(BSTR key, LONG* count);
	STDMETHOD(getExternalParamValue)(LONG keyindex, BSTR key, LONG valueindex, BSTR* value);
};

OBJECT_ENTRY_AUTO(__uuidof(TinyMsgInterface), CTinyMsgInterface)
